package cn.gong.moviekong.utils;

import android.util.Log;
import cn.gong.moviekong.config.Configs;

public class DebugUtils {
	public static final String TAG = "gexing";
	public static final String IMAGE_NULL = "imageNull";
	public static final String ERROR = "error";
	public static final String ISNULL = "isnull";
	public static final boolean ISTRACE = Configs.ISTRACE;

	public static void debug(String msg) {
		debug(TAG, msg);
	}

	public static void debug(String tag, String msg) {
		if (ISTRACE) {
			Log.i(tag, msg);
		}
	}

	private static void error(String tag, String msg) {
		if (ISTRACE) {
			Log.w(tag, msg);
		}
	}

	private static void error(String msg) {
		error(TAG, msg);
	}

	public static void exception(Exception e) {
		error("异常:");
		error("Caused by:" + e.toString());
		for (StackTraceElement stackTraceElement : e.getStackTrace()) {
			error(stackTraceElement.toString());
		}
	}

	public static void exception(String tag, Exception e) {
		error(tag, "异常:");
		error(tag, "Caused by:" + e.toString());
		for (StackTraceElement stackTraceElement : e.getStackTrace()) {
			error(tag, stackTraceElement.toString());
		}
	}

	public static <T> void isNull(String name, T obj) {
		if (ISTRACE) {
			if (obj == null) {
				Log.i(TAG, name + ":是空");
			} else {
				Log.i(TAG, name + ":不是空");
			}
		}
	}

	public static void imageNull(String msg) {
		if (ISTRACE) {
			Log.i(IMAGE_NULL, msg);
		}
	}
}
